//
//  FTSmartDeviceConst.m
//  FotileStyle
//
//  Created by wangspc on 2017/5/4.
//  Copyright © 2017年 Fotile. All rights reserved.
//

#import "FTSmartDeviceConst.h"


NSString *const FTNavigationNormalTintColorKey = @"FTNavigationNormalTintColorKey";

NSString *const FTNavigationDisableTintColorKey = @"FTNavigationDisableTintColorKey";

NSString *const FTViewBackgroundColorKey = @"FTViewBackgroundColorKey";

NSString *const FTNavigationBackgroundColorKey = @"FTNavigationBackgroundColorKey";

NSString *const FTViewColorForWhiteKey = @"FTViewColorForWhiteKey";

NSString *const FTViewColorForBlackKey = @"FTViewColorForBlackKey";

NSString *const FTViewColorRedKey = @"FTViewColorRedKey";

NSString *const FTViewDeviceShowBlaceColorkey = @"FTViewDeviceShowBlaceColorkey";

NSString *const FTKitchenSbName = @"Kitchen";

/// Used by 蒸箱 StoryBoard Name
NSString *const FTSteamerSbName = @"Steamer";

/// Used by 烤箱 StoryBoard Name
NSString *const FTOvenSbName = @"Oven";

/// Used by 微波炉 StoryBoard Name
NSString *const FTMicrowaveOvenSbName = @"MicrowaveOven";

/// Used by 蒸微一体机 StoryBoard Name
NSString *const FTSteamMicroMachineSbName = @"SteamMicroMachine";

/// Used by 油烟机 StoryBoard Name
NSString *const FTHoodSbName = @"Hood";

/// Used by 灶具 StoryBoard Name
NSString *const FTCookerSbName = @"Cooker";

/// Used by 消毒柜 StoryBoard Name
NSString *const FTSterilizerSbName = @"Sterilizer";

/// Used by 岛式机 StoryBoard Name
NSString *const FTIsLandHoodsSbName = @"IsLandHoods";

/// Used by 洗碗机 StoryBoard Name
NSString *const FTDishWasherSbName = @"DishWasher";

/// Used by 智能厨房控制中心IKCC StoryBoard Name
NSString *const FTIKCCNetSbName = @"IKCCNet";

/// Used by 光影油烟机 StoryBoard Name
NSString *const FTLightShadowHoodsSbName = @"LightShadowHoods";

/// Used by 光影蒸箱 StoryBoard Name
NSString *const FTLightShadowSteamerSbName = @"LightShadowSteamer";

/// Used by 光影微波炉 StoryBoard Name
NSString *const FTLightShadowMicrowaveOvenSbName = @"LSMicrowaveOven";

/// Used by 光影烤箱 StoryBoard Name
NSString *const FTLightShadowOvenSbName = @"LSOven";

UIColor *FTRGBA(uint32_t x, CGFloat alpha) {
    CGFloat b = (x & 0xff) / 255.0f; x >>= 8;
    CGFloat g = (x & 0xff) / 255.0f; x >>= 8;
    CGFloat r = (x & 0xff) / 255.0f;
    return [UIColor colorWithRed:r green:g blue:b alpha:alpha];
}

UIColor *FTRGB(uint32_t x) {
    return FTRGBA(x, 1.0f);
}
static NSMutableDictionary *colors() {
    static NSMutableDictionary *colors = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        colors = [@{
                    FTNavigationNormalTintColorKey: FTRGB(0xffffff),
                    FTNavigationDisableTintColorKey: FTRGBA(0xffffff, 0.2f),
                    FTViewBackgroundColorKey: FTRGB(0xf5f5f5),
                    FTNavigationBackgroundColorKey: FTRGB(0x2F2F2F),
                    FTViewColorForWhiteKey: FTRGB(0xffffff),
                    FTViewColorForBlackKey: FTRGB(0x000000),
                    FTViewColorRedKey: FTRGB(0xff6565),
                    FTViewDeviceShowBlaceColorkey: FTRGB(0x979797),
                    } mutableCopy];
    });
    return colors;
}
static NSMutableDictionary *smartDevices() {
    static NSMutableDictionary *smartDevices = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        smartDevices = [@{
                    FTSteamerSbName: @"SteamerMainViewController",
                    FTOvenSbName: @"OvenMainViewController",
                    FTMicrowaveOvenSbName: @"MicrowaveOvenMainViewController",
                    FTSteamMicroMachineSbName: @"SteamMicroMachineMainViewController",
                    FTHoodSbName: @"RangeHoodMainViewController",
                    FTCookerSbName: @"CookerMainViewController",
                    FTSterilizerSbName: @"SterilizerMainViewController",
                    FTIsLandHoodsSbName: @"IslandHoodViewController",
                    } mutableCopy];
    });
    return smartDevices;
}

UIColor *FTColor(NSString *colorKey) {
    return colors()[colorKey];
}

void FTUpdateButtonShadowLayer(UIButton *shdowButton) {
    
    shdowButton.layer.cornerRadius = 4;//25.f;
//    shdowButton.layer.shadowColor = FTColor(FTViewColorRedKey).CGColor;
//    shdowButton.layer.shadowOffset = CGSizeMake(-2, 10);
//    shdowButton.layer.shadowOpacity = 0.3;
    shdowButton.backgroundColor = FTColor(FTViewColorRedKey);
}
void FTUpdateButtonHighlighted(UIButton *button) {
    button.adjustsImageWhenHighlighted = NO;
}
NSString *FTSmartClassName(NSString *sbKey) {
    return smartDevices()[sbKey];
}

void FTVCClassSetClassNameForKey(NSString *key, NSString *className) {
    NSMutableDictionary *dict = smartDevices();
    [dict setObject:className forKey:key];
}

NSBundle *FTSmartBundle() {
    static NSBundle *bundle;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        // FTSmartConst 暂时修改
        bundle = [NSBundle bundleForClass:[NSObject class]];
    });
    return bundle;
}

NSBundle *FTSmarDefaultLocaleBundle() {
    static NSBundle *bundle;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSString *path = [FTSmartBundle() pathForResource:[FTSmartBundle() objectForInfoDictionaryKey:@"CFBundleDevelopmentRegion"] ofType:@"lproj"];
        bundle = [NSBundle bundleWithPath:path];
    });
    return bundle;
}

/// smart device cell margin
const CGFloat FTDeviceCollectionCellMargin = 10.0;

CGFloat FTDeviceCollectionCellWidth() {
    return (AKScreenWidth - FTDeviceCollectionCellMargin * 3) * (2.0 / 5.0);
}
CGFloat FTDeviceCollectionCellHeight() {
    return AKScreenHeight - 64 - 49 - 40;
}

NSIndexPath *FTSmartDeviceIndex(NSString *productID) {
   __block NSIndexPath *indexPath;
    
    [FTProductIDS() enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj enumerateObjectsUsingBlock:^(NSString *productId, NSUInteger idx2, BOOL * _Nonnull stop) {
            if ([productID isEqualToString:productId]) {
                indexPath = [NSIndexPath indexPathForRow:idx2 inSection:idx];
                *stop = YES;
            }
        }];
    }];
    return indexPath;
}

DeviceType FTSmartDeviceTypeFrom(NSString *productId) {
    NSIndexPath *indexPath = FTSmartDeviceIndex(productId);
#warning update this place
//    DeviceModel *model;
    if (indexPath) {
        Class cls = NSClassFromString(FTModelNameArray()[indexPath.section][indexPath.row]);
//        model = [[cls alloc] init];
    }
    return DeviceTypeSteamer;//model.type;
}


/**
 From device type get the current device name
 
 @param type device type
 @return device icon name
 */
NSString *FTDeviceName(DeviceType type) {
    NSString *ret = @"";
    switch (type) {
        case DeviceTypeSteamer:
            ret = @"steamer";
            break;
        case DeviceTypeOven:
            ret = @"oven";
            break;
        case DeviceTypeMicrowaveOven:
            ret = @"microwave_oven";
            break;
        case DeviceTypeRangeHood:
            ret = @"rangehood";
            break;
        case DeviceTypeCooker:
            ret = @"stove";
            break;
        case DeviceTypeSterilizer:
            ret = @"sterilizer";
            break;
        case DeviceTypeWaterHeater:
            ret = @"jingshuiqi";
            break;
        case DeviceTypeDishWasher:
            ret = @"dishwasher";
            break;
        case DeviceTypeWaterPurifier:
            ret = @"reshuiqi";
            break;
        case DeviceTypeSteamMicroMachine:
            ret = @"steam_machine";
            break;
        case DeviceTypeInternetIKCC:
            ret = @"wangguan";
            break;
            
        default:
            break;
    }
    return ret;
}
UIImage *FTSmartSelDeviceIcon(NSString *productId, BOOL selected) {
    // 通过产品ID 获取当前产品类型
    // 通过产品类型 获取产品字符串
    NSString *iconString = FTDeviceName(FTSmartDeviceTypeFrom(productId));
    if (iconString.length) {
        iconString = [NSString stringWithFormat:@"kitchen_icon_%@",iconString];
    }
    if (selected) {
        iconString = [iconString stringByAppendingString:@"_select"];
    }
    return [UIImage imageNamed:iconString];
}
